package com.zrwl.poscloud.xo.common;

import lombok.Data;
import org.springframework.http.ResponseEntity;

import java.util.List;
import java.util.Map;

/**
 * @author liuxiaolong
 * @date 2022/7/25
 * @description FuncTemplate请求
 */
@Data
public class FuncTemplateRequest {
    public static final String HeaderKey_Cookie = "Cookie";
    public static final String HeaderKey_Authorization = "Authorization";
    //发起请求的username
    private String username;
    //系统id
    private String systemId;
    //模块别名
    private String moduleAlias;
    //接口别名
    private String funcAlias;
    //请求参数
    private List<Object> params;
    //请求头中鉴权key
    private String headerAuthKey; //eg Cookie或者 Authorization
    //请求头中鉴权value
    private String headerAuthValue;
    //context params
    private Map<String,Object> contextParams;
    //成功响应的callback
    private ResponseCallBack callBack;
    //请求失败的callback
    private ResponseCallBack failCallBack;

    private boolean isCheckAlive;

    public FuncTemplateRequest(String username, String systemId, String moduleAlias, String funcAlias,
        List<Object> params, Map<String, Object> contextParams, String authKey, String authValue,
        ResponseCallBack callback, ResponseCallBack failCallBack) {
        this.username = username;
        this.systemId = systemId;
        this.moduleAlias = moduleAlias;
        this.funcAlias = funcAlias;
        this.params = params;
        this.contextParams = contextParams;
        this.headerAuthKey = authKey;
        this.headerAuthValue = authValue;
        this.callBack = callback;
        this.failCallBack = failCallBack;
        this.isCheckAlive = false;
    }

    public interface ResponseCallBack {
        void doInResponse(ResponseEntity<byte[]> responseEntity);
    }
}
